﻿package com.zkingsoft.actions.admin.pc;

import java.util.List;

import javax.annotation.Resource;

import com.zkingsoft.services.pc.PcFoodMaterialService;
import com.zkingsoft.services.pc.PcMenuCategoryService;
import com.zkingsoft.services.pc.PcMenuFoodService;
import com.zkingsoft.services.pc.PcMenuManageService;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.model.pc.PcFoodMaterial;
import com.zkingsoft.model.pc.PcMenuCategory;
import com.zkingsoft.model.pc.PcMenuFood;
import com.zkingsoft.model.pc.PcMenuManage;
import com.zkingsoft.authority.MatrixAdapter;
import com.zkingsoft.anotations.SaveRequestToken;
import com.zkingsoft.util.WebUtil;
import com.zkingsoft.constraint.BaseController;
import com.zkingsoft.externalInterface.common.Util;
import com.zkingsoft.pojo.AjaxResult;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zkingsoft.anotations.RemoveRequestToken;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2017-03-14 14:37
 */
@Controller
@RequestMapping(value = "admin/pcMenuManage")
public class PcMenuManageController extends BaseController{
	
	@Resource
	private PcMenuFoodService pcMenuFoodService;
	@Resource
	private PcMenuManageService pcMenuManageService;
	@Resource
	private PcFoodMaterialService pcFoodMaterialService;
	@Resource
	private PcMenuCategoryService PcMenuCategoryService;
	@Resource
	private MatrixAdapter matrixAdapter;
	
	
	
	//记录编辑前的值Before_Edit_Value
	public static final String BEV="PcMenuManage_BEV";
	
	public static final String fnCode = "PcMenuManage";
	public static final String search = fnCode + ":search";
	public static final String edit = fnCode + ":edit";
	public static final String del = fnCode + ":del";
	public static final String add = fnCode + ":add";
	
	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(PcMenuManage pcMenuManage, PaginationVO pageVo) {
		matrixAdapter.isBtnPermitted(search);
		return showList(pcMenuManageService, pcMenuManage, pageVo);
	}
   	
	/**
	 * 新增或者修改页面
	 */   
	@RemoveRequestToken	
   	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(PcMenuManage pcMenuManage) {
		if (pcMenuManage.getMenId() != null) {
	   		matrixAdapter.isBtnPermitted(edit);
	   		pcMenuManage.setMenId(((PcMenuManage)WebUtil.getSessionAttribute(BEV)).getMenId());
	   		AjaxResult result=modify(pcMenuManageService, WebUtil.getSessionAttribute(BEV), pcMenuManage, "菜谱 ");
			WebUtil.removeSessionAttribute(BEV);	
			return  result;
		} else {
			matrixAdapter.isBtnPermitted(add);
			return add(pcMenuManageService, pcMenuManage, "菜谱");
		}
	}
	
   	/**
	 * 进入修改界面
	 */   
	@SaveRequestToken
   	@RequestMapping(value = "/editForm")
	public String editForm(Long id) {
		matrixAdapter.isBtnPermitted(edit);
		PcMenuManage pcMenuManage;
		if (id != null) {
			pcMenuManage = pcMenuManageService.findById(id);
			WebUtil.getRequest().setAttribute("obj", pcMenuManage);
			WebUtil.setSessionAttribute(BEV, pcMenuManage);
			/*原材料——菜谱数据*/
			PcMenuFood pcMenuFood=new PcMenuFood();
			pcMenuFood.setMenId(id);
			List<PcMenuFood> materials = pcMenuFoodService.findByModel(pcMenuFood);
			WebUtil.getRequest().setAttribute("materials", materials);
		} 
		return "admin/pc/PcMenuManage-form";
	}
	/**
	 * 显示菜名
	 */
	@RequestMapping(value = "/all")
	public @ResponseBody AjaxResult all() {
		return findByModel(pcMenuManageService, null);
	}
   	/**
	 * 删除
	 */  
 	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		matrixAdapter.isBtnPermitted(del);
		return remove(pcMenuManageService, keys);
	}
  
}